Skip to content

fix(images): use node base_url + resolve prefix for custom image providers (#3205) - #3208

Merged
diegosouzapw merged 1 commit into
release/v3.8.11from
fix/3205-image-gen-baseurl
Jun 5, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.11from
fix/3205-image-gen-baseurl

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Closes #3205

Custom image-generation providers read credentials.baseUrl (always undefined) → fell back to the Gemini endpoint (401). Now resolves providerSpecificData.baseUrl like the chat path, and rewrites prefix/model to the internal node id before the exact-id lookup.

Test: tests/unit/image-generation-baseurl-3205.test.ts. Thanks @ngocquynh85.

…mage providers (#3205)

The image-generation handler read credentials.baseUrl (always undefined),
so custom OpenAI-compatible image providers fell back to the Gemini endpoint
(401). Resolve from providerSpecificData.baseUrl like the chat path, and
rewrite prefix/model to the internal node id before the exact-id lookup.

Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@diegosouzapw
diegosouzapw merged commit fa0aa1e into release/v3.8.11 Jun 5, 2026
2 checks passed
@diegosouzapw
diegosouzapw deleted the fix/3205-image-gen-baseurl branch June 5, 2026 05:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a02ffb5a1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +181 to +182
if (!parseImageModel(body.model).provider) {
body.model = await resolveImageModelPrefix(body.model);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize custom image model before policy checks

When a client uses the newly supported user prefix (myImg/gpt-image-2) with an API key that has model restrictions or disableNonPublicModels, the policy check still runs against the prefix before it is rewritten to the internal <nodeId>/<model> id stored in customModels. That makes a key configured for the model ids returned by GET /v1/images/generations reject valid prefixed requests (and also evaluates token limits against the wrong model name). Move the prefix resolution ahead of enforceApiKeyPolicy or have the policy evaluate the resolved id.

Useful? React with 👍 / 👎.

Comment on lines +310 to +313
baseUrl: resolveImageBaseUrl(
credentials,
`https://generativelanguage.googleapis.com/v1beta/openai/images/generations`
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor custom endpoint paths for image nodes

Custom OpenAI-compatible nodes can store a non-default endpoint path in providerSpecificData.chatPath, but this resolver only uses the base URL and then always appends /images/generations. For an image node configured with a gateway-specific path such as baseUrl=https://gateway.example/v1 and chatPath=/custom/images, requests are sent to /v1/images/generations instead of the configured endpoint, so those otherwise valid custom providers still fail.

Useful? React with 👍 / 👎.

@kilo-code-bot

kilo-code-bot Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Additional Issues Found | Recommendation: Code looks sound

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Files Reviewed (3 files)
  • open-sse/handlers/imageGeneration.ts — Added resolveImageBaseUrl helper and wiring for custom OpenAI-compatible image providers
  • src/app/api/v1/images/generations/route.ts — Added resolveImageModelPrefix for user-prefixed custom image model resolution
  • tests/unit/image-generation-baseurl-3205.test.ts — New unit tests covering the baseUrl resolution logic
Other Observations (not in diff)

No issues in unchanged code that require attention.

Notes

  • The PR correctly addresses issue Custom images-generations providers do not use provider node base_url or prefix/combo resolution #3205 by reading credentials.providerSpecificData.baseUrl (matching the chat path pattern) instead of only the top-level credentials.baseUrl.
  • resolveImageBaseUrl handles trailing-slash normalization and double-append prevention for URLs already ending in /images/generations.
  • resolveImageModelPrefix correctly mirrors the prefix-matching behavior used in the chat resolver, falling back gracefully on DB errors.
  • Unit tests cover the primary resolution priority and fallback cases.

Reviewed by step-3.7-flash-20260528 · 858,084 tokens

// Prefer an explicit user-defined prefix match; node.id (internal UUID) is
// already handled by the exact-id loop, so only rewrite when the prefix
// differs from the node id.
const matched = nodes.find((node: any) => node.prefix === prefixPart);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: node: any bypasses TypeScript type safety

getProviderNodes returns typed objects with prefix, id, etc. Using any discards that type information. Consider typing the parameter properly (e.g. using the return type of getProviderNodes) so the compiler can catch shape mismatches if the schema changes.

if (!rest) return modelStr;

try {
const nodes = await getProviderNodes({ type: "openai-compatible" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: getProviderNodes({ type: "openai-compatible" }) hits the DB on every prefixed-model request

If this code path is exercised frequently, consider caching the node list (e.g. via readCache.ts or an in-memory cache with invalidation on provider changes) to avoid repeated SQLite reads in the request hot path.

HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…mage providers (cheaper-inference#3205) (cheaper-inference#3208)

The image-generation handler read credentials.baseUrl (always undefined),
so custom OpenAI-compatible image providers fell back to the Gemini endpoint
(401). Resolve from providerSpecificData.baseUrl like the chat path, and
rewrite prefix/model to the internal node id before the exact-id lookup.

Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
…mage providers (cheaper-inference#3205) (cheaper-inference#3208)

The image-generation handler read credentials.baseUrl (always undefined),
so custom OpenAI-compatible image providers fell back to the Gemini endpoint
(401). Resolve from providerSpecificData.baseUrl like the chat path, and
rewrite prefix/model to the internal node id before the exact-id lookup.

Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…mage providers (cheaper-inference#3205) (cheaper-inference#3208)

The image-generation handler read credentials.baseUrl (always undefined),
so custom OpenAI-compatible image providers fell back to the Gemini endpoint
(401). Resolve from providerSpecificData.baseUrl like the chat path, and
rewrite prefix/model to the internal node id before the exact-id lookup.

Co-authored-by: ngocquynh85 <ngocquynh85@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant